package cn.iocoder.yudao.module.design.dal.mysql.flow;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.design.controller.admin.flow.vo.FlowBaseVO;
import cn.iocoder.yudao.module.design.controller.admin.flow.vo.FlowExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.flow.vo.FlowPageReqVO;
import cn.iocoder.yudao.module.design.dal.dataobject.flow.FlowCountDO;
import cn.iocoder.yudao.module.design.dal.dataobject.flow.FlowDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 流程信息 Mapper
 *
 * @author czw
 */
@Mapper
public interface FlowMapper extends BaseMapperX<FlowDO> {

    default PageResult<FlowDO> selectPage(FlowPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FlowDO>()
                .eqIfPresent(FlowDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(FlowDO::getDesignerId, reqVO.getDesignerId())
                .likeIfPresent(FlowDO::getFlowName, reqVO.getFlowName())
                .eqIfPresent(FlowDO::getIsMainCd, reqVO.getIsMainCd())
                .eqIfPresent(FlowDO::getPreId, reqVO.getPreId())
                .eqIfPresent(FlowDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(FlowDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(FlowDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(FlowDO::getCost, reqVO.getCost())
//                .eqIfPresent(FlowDO::getPicId, reqVO.getPicId())
                .betweenIfPresent(FlowDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(FlowDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(FlowDO::getRemark, reqVO.getRemark())
                .orderByDesc(FlowDO::getId));
    }

    default List<FlowDO> selectList(FlowExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FlowDO>()
                .eqIfPresent(FlowDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(FlowDO::getDesignerId, reqVO.getDesignerId())
                .likeIfPresent(FlowDO::getFlowName, reqVO.getFlowName())
                .eqIfPresent(FlowDO::getIsMainCd, reqVO.getIsMainCd())
                .eqIfPresent(FlowDO::getPreId, reqVO.getPreId())
                .eqIfPresent(FlowDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(FlowDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(FlowDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(FlowDO::getCost, reqVO.getCost())
                .betweenIfPresent(FlowDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(FlowDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(FlowDO::getRemark, reqVO.getRemark())
                .orderByDesc(FlowDO::getId));
    }

    default List<FlowDO> selectList(FlowBaseVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FlowDO>()
                .eqIfPresent(FlowDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(FlowDO::getDesignerId, reqVO.getDesignerId())
                .likeIfPresent(FlowDO::getFlowName, reqVO.getFlowName())
                .eqIfPresent(FlowDO::getIsMainCd, reqVO.getIsMainCd())
                .eqIfPresent(FlowDO::getPreId, reqVO.getPreId())
                .eqIfPresent(FlowDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(FlowDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(FlowDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(FlowDO::getCost, reqVO.getCost())
                .eqIfPresent(FlowDO::getRemark, reqVO.getRemark())
                .orderByDesc(FlowDO::getId));
    }
    default List<FlowDO> selectList(FlowBaseVO reqVO,Integer flowCd) {
        return selectList(new LambdaQueryWrapperX<FlowDO>()
                .eqIfPresent(FlowDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(FlowDO::getDesignerId, reqVO.getDesignerId())
                .likeIfPresent(FlowDO::getFlowName, reqVO.getFlowName())
                .eqIfPresent(FlowDO::getIsMainCd, reqVO.getIsMainCd())
                .eqIfPresent(FlowDO::getPreId, reqVO.getPreId())
                .eqIfPresent(FlowDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(FlowDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(FlowDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(FlowDO::getCost, reqVO.getCost())
                .eqIfPresent(FlowDO::getRemark, reqVO.getRemark())
                .orderByDesc(FlowDO::getId));
    }

    default List<FlowDO> selectListByStatus(Integer status) {
        return selectList(FlowDO::getStatusCd, status);
    }

    List<Map>  getFlowListByCondition(@Param("houseId") Long houseId,@Param("flowCd")String flowCd, @Param("userId")Long userId,@Param("roleId")Long roleId);

    List<Map>  getFlowListByConditionAdmin(@Param("houseId") Long houseId,@Param("flowCd")String flowCd);


    List<FlowCountDO> getPurchaseFlowCountList(@Param("ids")Collection<Long> ids, @Param("userId") Long loginUserId);
}
